package com.hhit.bigscreenbackmanage.common;



/**
 * @Description: 返回工具类
 * @Author: qianchengcheng
 * @Date: 2021/4/12 16:14
 * @Param:
 * @Return:
 **/
public class Response<T> {

    // 状态码,成功为0,失败为1,也封装成常量类
    private Integer code;

    // 消息,成功消息或者失败消息
    private String message;

    // 要返回的数据
    private T data;

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    private Response(Integer code, String message){
        this.code = code;
        this.message = message;
    }

    private Response(Integer code, String message, T data){
        this.code = code;
        this.message = message;
        this.data = data;
    }

    /**
     * 状态码 + 成功提示信息
     */
    public static <T> Response<T> createResponseBySuccess(String message){
        return new Response<>(BizConstants.SUCCESS,message);
    }

    /**
     * 状态码 + 成功提示信息 + 数据
     */
    public static <T> Response<T> createResponseBySuccess(String message,T data){
        return new Response<>(BizConstants.SUCCESS,message,data);
    }

    /**
     * 状态码 + 错误信息
     */
    public static <T> Response<T> createResponseByError(String message){
        return new Response<>(BizConstants.ERROR,message);
    }

    public static <T> Response<T> createResponseByInterfaceException(String message){
        return new Response<>(BizConstants.INTERFACE_EXCEPTION,message);
    }
}
